import 'package:chewie/chewie.dart';
import 'package:get/get.dart';
import 'package:video_player/video_player.dart';

import 'state.dart';

class VideoPlayController extends GetxController {
  final VideoPlayState state = VideoPlayState();
  late VideoPlayerController videoPlayerController;
  late ChewieController chewieController;

  @override
  void onInit() {
    super.onInit();
    state.title = Get.arguments['title'];
    state.url = Get.arguments['url'];
    videoPlayerController =
        VideoPlayerController.networkUrl(Uri.parse(state.url ?? ''));
    chewieController = ChewieController(
      videoPlayerController: videoPlayerController,
      aspectRatio: 3 / 2,
      showOptions: false,
      autoPlay: true,
      looping: true,
    );
  }

  @override
  void onClose() {
    videoPlayerController.dispose();
    chewieController.dispose();
    Get.delete<VideoPlayController>();
    super.onClose();
  }
}
